from django.shortcuts import render_to_response
from django.template import RequestContext
from inscricoes.models import Palestra, Proposta
from conteudo.models import Post, Publicidade
from configuration.models import MenuSite
from django.http import HttpResponse
from configuration.models import PageData

def index(request, res=None):

    page = 'noticias.html'
    posts = Post.objects.all().order_by('-date')


    numeroDePostsPorPagina = 6;
    numeroDePosts = len(posts)

    numeroDaPagina = 1
    if res != None:
        numeroDaPagina = int(res)

    indexBase = (numeroDaPagina - 1) * numeroDePostsPorPagina
    posts = posts[indexBase: indexBase + numeroDePostsPorPagina]

    proximaPagina = numeroDaPagina + 1
    paginaAnterior = numeroDaPagina - 1
    
    exibirPaginaAnterior = False
    if paginaAnterior > 0:
        exibirPaginaAnterior = True

    exibirProximaPagina = False
    if indexBase + numeroDePostsPorPagina < numeroDePosts:
        exibirProximaPagina = True

    data = PageData()

    return render_to_response('index.html', locals(),
            context_instance=RequestContext(request))


